﻿using Prism.Mvvm;
using Prism.Services.Dialogs;
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Company.Core.Dialogs
{
    /// <summary>
    /// 需要弹窗的ViewModel都需要继承此基类（此基类实现了 IDialogAware 弹窗接口）
    /// </summary>
    public class DialogViewModelBase : ReactiveObject, IDialogAware
    {
        public string Title { get; set; } = "弹窗标题";

        /// <summary>
        /// 请求关闭事件
        /// </summary>
        public event Action<IDialogResult> RequestClose;

        /// <summary>
        /// 是否允许关闭
        /// </summary>
        /// <returns></returns>
        public virtual bool CanCloseDialog()
        {
            return true;
        }

        /// <summary>
        /// 关闭后
        /// </summary>
        public virtual void OnDialogClosed()
        {

        }

        /// <summary>
        /// 弹窗打开时
        /// </summary>
        /// <param name="parameters"></param>
        /// <exception cref="NotImplementedException"></exception>
        public virtual void OnDialogOpened(IDialogParameters parameters)
        {
        }

        protected virtual void CloseDialog(ButtonResult buttonResult, IDialogParameters parameters = null)
        {
            RequestClose?.Invoke(new DialogResult(buttonResult, parameters));
        }
    }
}
